package server.config;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * @ClassName CustomRoutingDataSource
 * @Description
 * @Author Jingxiao.Ye
 * @Date 2021/12/21 上午12:14
 * @Version V1.0
 * @Since JDK 11
 */
public class CustomRoutingDataSource extends AbstractRoutingDataSource {

    private int status = 0;

    public void setWrite(){
        status = 1;
    }

    public void setRead(){
        status = 0;
    }

    @Override
    protected Object determineCurrentLookupKey() {
        //如果是查询的获得
        if(status == 0){
            return "read";
        }else return "write";
    }
}
